<%--
  author: winkyle
  date: 2018/11/25
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html lang="en">
<head>
    <!-- jsp文件头和头部 -->
    <%@ include file="../base/top.jsp"%>
</head>
<body class="no-skin">
<!-- /section:basics/navbar.layout -->
<div class="main-container" id="main-container">
    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <div class="hr hr-18 dotted hr-double"></div>
                <div class="row">
                    <div class="col-xs-12">

                        <form action="" name="userForm" id="userForm" method="post">
                            <input type="hidden" name="USER_ID" id="user_id" value=""/>
                            <input type="text" name="success" id="success" style="display: none"/>
                            <input type="text" name="msg" id="msg" style="display: none"/>
                            <div id="zhongxin" style="padding-top: 13px;">
                                <table id="table_report" class="table table-striped table-bordered table-hover">
                                    <tr>
                                        <td style="width:79px;text-align: right;padding-top: 13px;">任务名称:</td>
                                        <td><input type="text" name="taskName" id="taskName" value="${taskInfo.taskName}" maxlength="32"  style="width:98%;"/></td>
                                    </tr>
                                    <tr>
                                        <td style="width:79px;text-align: right;padding-top: 13px;">任务类型:</td>
                                        <td id="juese">
                                            <select class="chosen-select form-control" name="taskType" id="taskType" data-placeholder="请选择任务" style="vertical-align:top;" style="width:98%;" >
                                                <option value="0"  ${taskInfo.taskType==0?'selected':''}>单人任务</option>
                                                <option value="1"  ${taskInfo.taskType==1?'selected':''}>小组任务</option>
                                            </select>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="width:79px;text-align: right;padding-top: 13px;">开始时间:</td>
                                        <td><input type="datetime" name="mydate" id="taskStartTime" placeholder="yyyy/MM/dd HH:mm" value="<fmt:formatDate value="${taskInfo.taskStartTime}" pattern="yyyy/MM/dd HH:mm"/>" maxlength="32"  style="width:98%;"/></td>
                                    </tr>
                                    <tr>
                                        <td style="width:79px;text-align: right;padding-top: 13px;">结束时间:</td>
                                        <td><input type="datetime" name="mydate" id="taskEndTime" placeholder="yyyy/MM/dd HH:mm" value="<fmt:formatDate value="${taskInfo.taskEndTime}" pattern="yyyy/MM/dd HH:mm"/>" maxlength="32"  style="width:98%;"/></td>
                                    </tr>
                                    <tr>
                                        <td style="width:79px;text-align: right;padding-top: 13px;">任务说明:</td>
                                        <td><textarea id="taskDescription" name="description" class="form-control" rows="8">${taskInfo.taskDescription}</textarea></td>
                                    </tr>
                                    <tr>
                                        <td style="text-align: center;" colspan="10">
                                            <a class="btn btn-mini btn-primary" onclick="save();">保存</a>
                                            <a class="btn btn-mini btn-danger" onclick="top.Dialog.close();">取消</a>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                            <div id="zhongxin2" class="center" style="display:none"><br/><br/><br/><br/><img src="static/images/jiazai.gif" /><br/><h4 class="lighter block green"></h4></div>
                        </form>

                    </div>
                    <!-- /.col -->
                </div>
                <!-- /.row -->
            </div>
            <!-- /.page-content -->
        </div>
    </div>
    <!-- /.main-content -->
    <!-- 返回顶部 -->
    <a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
        <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
    </a>

</div>
<!-- /.main-container -->
<!-- basic scripts -->
<!-- 页面底部js¨ -->
<%@ include file="../base/foot.jsp"%>

<script type="text/javascript">
    $(top.hangge());
    function checkIsValidDate(str)
    {
        var   reg   =  /^(\d{1,4})(\/)(\d{1,2})(\/)(\d{1,2}) (\d{1,2}):(\d{1,2})$/;
        var   arr   =   str.match(reg);
        if (arr==null){
            return   false;
        }
        return   true;
    }

    function save() {
        var taskInfo = {
            teachCourseId:"${teachCourseId}",
            taskName:$("#taskName").val(),
            taskType:$("#taskType").val(),
            taskStartTime:$("#taskStartTime").val(),
            taskEndTime:$("#taskEndTime").val(),
            taskDescription:$("#taskDescription").val()
        }
        if(taskInfo.taskName==""||taskInfo.taskType==""||taskInfo.taskStartTime==""||taskInfo.taskEndTime==""||taskInfo.taskDescription==""){
            top.operateError("输入不能为空");
            return;
        }
        if(!checkIsValidDate($("#taskStartTime").val())){
            top.operateError("开始时间格式错误");
            return;
        }
        if(!checkIsValidDate($("#taskEndTime").val())){
            top.operateError("结束时间格式错误");
            return;
        }
        if("${"edit".equals(type)}"){
            taskInfo.taskId = "${taskInfo.taskId}";
        }
        console.log(taskInfo);
        $.ajax({
            url:"task/${type}_task_info",
            type:"POST",
            data: taskInfo,
            dataType:'json',
            cache: false,
            success:function (data) {
                console.log(data);
                $("#success").val(data["success"]);
                $("#msg").val(data["msg"]);
                //关闭一定要写在ajax执行完成之后
                top.Dialog.close();
            }
        })

    }

</script>
</body>
</html>
